
const mongoose = require("mongoose");
mongoose.connect("mongodb://127.0.0.1:27017/test")

const tagSchema =new mongoose.Schema({
//  text:String,
 text:{
     type:String,
     minlength:2,
     maxlength:12
 }
})
/* 
新增
*/

const contentSchema = new mongoose.Schema({
    title:{
        type:String,
        minlength:6,
        maxlength:12
    },
    content:{
        type:String,
        minlength:10,
        maxlength:50
    },
    top:{
        type:Boolean
    }
})

const userSchema = new mongoose.Schema({
    username:{
        type:String,
        minlength:5,
        maxlength:20
    },
    password:{
        type:Number,
        minlength:6,
        maxlength:18
    },
    
    emal: {
        type: String,
        validate: {
          validator: function(v) {
            return /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(v);
          },
          message: '{VALUE} is not a valid phone number!'
        },
        required: [true, 'emal格式不对']
      }
    
})

/* 
新增
*/
const tagModel = new mongoose.model("tag",tagSchema);
const contentModel = new mongoose.model("content",contentSchema);
const userModel = new mongoose.model("user",userSchema)
// tagModel.

module.exports ={tagModel,contentModel,userModel};

  